/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package amd.core.search;

import amd.core.data.ListDocWeight;
import amd.core.data.ListTermFrequency;
import amd.core.extraction.TermsExtractor;
import amd.database.ConnectDB;
import amd.database.DbTermDocument;
import amd.database.QueryNoResultException;
import java.util.ArrayList;

/**
 *
 * @author Latifah Dwi Nurachma
 */
public class SearchDocRelevant {
    public static ListDocWeight search(ConnectDB conn, String stringInput) throws QueryNoResultException{
        int i = 0;
        ListDocWeight listDoc = new ListDocWeight();
        ListTermFrequency listTerm = TermsExtractor.extract(stringInput);
        if(!listTerm.isEmpty()){
            String[] terms = new String[listTerm.size()];
            while (i<listTerm.size()){
                terms[i] = listTerm.get(i).getContent();
                i++;
            }
            listDoc = DbTermDocument.getIdDocSumWeightByTermContent(conn, terms);
        }
        return listDoc;
    }

    public static ArrayList<ArrayList<String>> search(ConnectDB conn, String stringInput, float treshold) throws QueryNoResultException {
        int i = 0;
        ArrayList<ArrayList<String>> listDoc = new ArrayList<ArrayList<String>>();
        ListTermFrequency listTerm = TermsExtractor.extract(stringInput);
        if(!listTerm.isEmpty()){
            String[] terms = new String[listTerm.size()];
            while (i<listTerm.size()){
                terms[i] = listTerm.get(i).getContent();
                i++;
            }
             listDoc = DbTermDocument.getDocByTermContent(conn, terms, treshold);
        }
        return listDoc;

    }

    public static ArrayList<ArrayList<String>> search(ConnectDB conn, String stringInput, float treshold, int page) throws QueryNoResultException{
        int i = 0;
        int limit=10;
        ArrayList<ArrayList<String>> listDoc = new ArrayList<ArrayList<String>>();
        ListTermFrequency listTerm = TermsExtractor.extract(stringInput);
        if(!listTerm.isEmpty()){
            String[] terms = new String[listTerm.size()];
            while (i<listTerm.size()){
                terms[i] = listTerm.get(i).getContent();
                i++;
            }
             listDoc = DbTermDocument.getDocByTermContent(conn, terms, treshold, (limit*page), limit);
        }
        return listDoc;
    }
}
